package Thread.letter;

import java.util.concurrent.TimeUnit;

public class Test5 {
}

class Test4Thread1 implements Runnable {
    private Object lock;

    public Test4Thread1(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        try {
            while (true) {
                synchronized (lock) {
                    System.out.println("线程1开始sleep");
                    TimeUnit.SECONDS.sleep(5);
                    System.out.println("线程1sleep完毕");
                }
            }
        } catch (Exception e) {
        }
    }
}

class Test4Thread2 implements Runnable {
    private Object lock;

    public Test4Thread2(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        try {
            while (true) {
                synchronized (lock) {
                    System.out.println("线程2开始sleep");
                    TimeUnit.SECONDS.sleep(5);
                    System.out.println("线程2sleep完毕");
                }
            }
        } catch (Exception e) {

        }
    }
}

class Test4Thread3 implements Runnable {
    private Object lock;

    public Test4Thread3(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        try {
            while (true) {
                synchronized (lock) {
                    System.out.println("线程3开始wait");
                    lock.wait();
                    System.out.println("线程3wait完毕");
                }
            }
        } catch (Exception e) {
        }
    }
}

class Test4Thread4 implements Runnable {
    private Object lock;

    public Test4Thread4(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        try {
            while (true) {
                synchronized (lock) {
                    System.out.println("线程4开始wait");
                    lock.wait();
                    System.out.println("线程4wait完毕");
                }
            }
        } catch (Exception e) {
        }
    }
}